package 力扣._73_矩阵置零;

public class Solution2 {
    public void setZeroes(int[][] matrix) {
        //记录哪一行有0，那一列有0
        int[] row = new int[matrix.length];
        int[] col = new int[matrix[0].length];
        for (int i = 0; i < row.length; i++) {
            for (int j = 0; j < col.length; j++)
                if (matrix[i][j] == 0) {
                    row[i] = 1;
                    break;
                }
        }
        for (int j = 0; j < col.length; j++) {
            for (int i = 0; i < row.length; i++)
                if (matrix[i][j] == 0) {
                    col[j] = 1;
                    break;
                }
        }
        for (int i = 0; i < row.length; i++)
            if (row[i] == 1)
                //行置零
                for (int k = 0; k < matrix[0].length; k++)
                    matrix[i][k] = 0;

        for (int j = 0; j < col.length; j++)
            if (col[j] == 1)
                //列置零
                for (int k = 0; k < matrix.length; k++)
                    matrix[k][j] = 0;


    }

    public static void main(String[] args) {
        //[[0,1,2,0],[3,4,5,2],[1,3,1,5]]
        int[][] matrix = new int[][]{{0,1,2,0},{3,4,5,2},{1,3,1,5}};
        new Solution2().setZeroes(matrix);
    }
}
